# -*- coding: utf-8 -*-

from odoo import models, fields, api


class StockPicking(models.Model):
    _inherit= 'stock.picking'

    salesman_id=fields.Many2one('res.users',compute='compute_salesman_id')
    def compute_salesman_id(self):
        for r in self:
            salesman_id=r.move_lines.mapped('sale_line_id').mapped('salesman_id')
            if not salesman_id:
                salesman_id=r.move_lines.mapped('purchase_line_id').mapped('order_id').mapped('user_id')
            if salesman_id:
                r.salesman_id=salesman_id.id


class StockLocation(models.Model):
    _inherit = 'stock.location'
    _sql_constraints = [
        ('partner_name', 'unique (name)', "名字必须唯一"),
    ]


